package xcmg.device.service.basic;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xcmg.device.infra.ErrorCode;
import xcmg.device.infra.exception.CommonBusiExceptions;
import yb.ecp.fast.feign.FastGenClient;
import yb.ecp.fast.infra.infra.ActionResult;

@Service
public class CommonGenService {
    @Autowired
    private FastGenClient fastGenClient;

    public String textIdWithException(String errMsg) {
        ActionResult<String> textResult = fastGenClient.textGuid();
        if (textResult.getCode() != ErrorCode.Success.getCode() || StringUtils.isBlank(textResult.getValue())) {
            throw new CommonBusiExceptions(errMsg);
        }
        return textResult.getValue();
    }

    public String textIdWithException() {
        ActionResult<String> textResult = fastGenClient.textGuid();
        if (textResult.getCode() != ErrorCode.Success.getCode() || StringUtils.isBlank(textResult.getValue())) {
            throw new CommonBusiExceptions("FastGenClient服务异常，请稍后重试");
        }
        return textResult.getValue();
    }

    public Long longIdWithException() {
        ActionResult<Long> textResult = fastGenClient.numberGuid();
        if (textResult.getCode() != ErrorCode.Success.getCode() || null == textResult.getValue()) {
            throw new CommonBusiExceptions("FastGenClient服务异常，请稍后重试");
        }
        return textResult.getValue();
    }
}
